package demo.thread.synMethod;

/**
 * 线程B
 */
public class ThreadB extends Thread{

    public ThreadB(String name) {
        super(name);
    }

    @Override
    public synchronized void run() {
        ShareData shareData = ShareData.getInstance();
        try {
            System.out.println("B:等待flag变为ture");
            shareData.waitForFlag(); // 等待flag变为true后继续执行
            System.out.println("B:flag变为true了");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
